// =========================
//
// PageBrowserButton Class
// Controls the Button that Opens/Closes Page Browser
//
// =========================

var pageBrowserButtonCurrentState = "pause";
var pageBrowserButtonIsMouseOver = false;
var pageBrowserButtonIsMouseDown = false;
function enterPageBrowserButton (s,e)
{
	var over = wpf.findName(pageBrowserButtonCurrentState + "_over");
	var normal = wpf.findName(pageBrowserButtonCurrentState + "_normal");
    var down = wpf.findName(pageBrowserButtonCurrentState + "_down");
    
	if (pageBrowserButtonIsMouseDown == true)
	{
	  normal.opacity = 0;
 	  over.opacity = 0;
 	  down.opacity = 1;
	}
	else
	{
	  normal.opacity = 0;
 	  over.opacity = 1;
	}
	
	pageBrowserButtonIsMouseOver = true;
}

function leavePageBrowserButton (s,e)
{
	var over = wpf.findName(pageBrowserButtonCurrentState + "_over");
	var normal = wpf.findName(pageBrowserButtonCurrentState + "_normal");
	var down = wpf.findName(pageBrowserButtonCurrentState + "_down");
	
	if (pageBrowserButtonIsMouseDown == true)
	{
	  normal.opacity = 0;
 	  over.opacity = 1;
 	  down.opacity = 0;
	}
	else
	{
      normal.opacity = 1;
 	  over.opacity = 0;
	}
	
	pageBrowserButtonIsMouseOver = false;
}

function downPageBrowserButton (s,e)
{
	var over = wpf.findName(pageBrowserButtonCurrentState + "_over");
	var down = wpf.findName(pageBrowserButtonCurrentState + "_down");
	
    down.opacity = 1;
    over.opacity = 0;
    
    pageBrowserButtonIsMouseDown = true;
    wpf.findName("pageBrowserButton").captureMouse();
}

function upPageBrowserButton (s,e)
{
 	var over = wpf.findName(pageBrowserButtonCurrentState + "_over");
	var normal = wpf.findName(pageBrowserButtonCurrentState + "_normal");
	var down = wpf.findName(pageBrowserButtonCurrentState + "_down");
    var _sb = wpf.findName("openPageBrowserSB");
	
	if (pageBrowserButtonIsMouseOver == true)
	{
	  // change button state
	  if (pageBrowserButtonCurrentState == "pause")
	  {
	    pageBrowserButtonCurrentState = "play";
	    // Begin animation
	    _sb.begin();
	  }
	  else
	  {
	    pageBrowserButtonCurrentState = "pause";
	    // Stop animation
	    _sb.stop();
	  }
	  
	  newover = wpf.findName(pageBrowserButtonCurrentState + "_over");
	  
	  newover.opacity = 1;
	  down.opacity = 0;
	}
	else
	{
      normal.opacity = 1;
	  down.opacity = 0;
	  over.opacity = 0;
	}
	
	pageBrowserButtonIsMouseDown = false;
	wpf.findName("pageBrowserButton").releaseMouseCapture();

}